package org.hot100_1;

public class leetcode4 {
    public void moveZeroes(int[] nums) {
        if (nums==null || nums.length==1){
            return;
        }
        int left = 0;
        int right =0;

        /**
         *nums[left]=nums[right];
         *nums[right]=0;
         *使用上面的语句来交换数值，如果left和right指向的是同一个值，那么会将nums[right]!=0变为nums[right]=0
         */
        while (right<nums.length){
            if (nums[right]!=0){
               swap(nums,left,right);
               left++;
            }
            right++;
        }
    }

    private void swap (int [] nums,int index1,int index2){
        int temp = nums[index1];
        nums[index1]=nums[index2];
        nums[index2]=temp;
    }


}
